package ai.people.netmon.youtube.view.service.impl;

import ai.people.netmon.framework.domain.twitter.probe.request.UserWebRequest;
import ai.people.netmon.framework.domain.youtube.view.YoutubeAccountView;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.youtube.view.mapper.YoutubeAccountViewMapper;
import ai.people.netmon.youtube.view.service.YoutubeAccountViewService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 说明
 *
 * @author zhenglin
 * @since 2022/3/17
 */
@Service
public class YoutubeAccountViewServiceImpl extends ServiceImpl<YoutubeAccountViewMapper, YoutubeAccountView> implements YoutubeAccountViewService {

    @Autowired
    YoutubeAccountViewMapper viewMapper;

    @Override
    public PageResponse<YoutubeAccountView> listViews(UserWebRequest request) {
        Page<YoutubeAccountView> page = new Page<>(request.getOriginPageNo(),request.getPageSize());

        IPage<YoutubeAccountView> result = viewMapper.selectPageCustom(page,request);
        return PageResponse.builder(result);
    }

    @Override
    public YoutubeAccountView getView(String accountName) {
        LambdaQueryWrapper<YoutubeAccountView> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(YoutubeAccountView::getAccountName,accountName);
        return getOne(queryWrapper);
    }
}
